{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Parameters in BioCRNpyler\n", "BioCRNpyler has a flexible parameter system allowing for models to be rapidly produced using very few parameters common across many reactions and then refined so that each mechanisms and components have unique reaction parameters derived from the literature or experiments. This parameter system is designed to work automatically, so all users have to do is specify a parameter file of the proper format or a parameter dictionary which can be loaded into Mixtures and Components using the parameter_file and/or parameters (for dictionaries) keywords. Parameters from multiple sources can be used together.\n", "\n", "Parameters passed into a Component supercede mixture level parameters in reactions produced by that Component.\n", "\n", "#### Parameter File Overview:\n", "Parameter files can be .tsv (or .txt) or .csv. The first line of the file should contain column headings. The following headings are required (in any order): mechanism_id, part_id, param_name, param_val (spaces can be substituted for underscores and headings are not case sensitive). mechanism_id is the name of the Mechanism or the kind of mechanism that will use this parameter, for example \"transcription\" or \"transcription_mm\" for Mechalis-Menten transcription would go in this column. part_id refers to the name supplied by the Component that will use this mechanism, for example \"ptet\" for a tet repressed promoter and \"ptet_leak\" for leak reactions of that promoter. param_name refers to the name of the model parameter, for example \"ktx\", \"kb\", or \"ku\". The value of these columns is case sensitive and underscores are different from spaces. All these parameter headings (if they are not empty) are required to be alpha-numeric (plus single internal underscores) and start with a letter.\n", "\n", "\n", "#### Viewing Parameters Used in a Model\n", "The easiest way to examine which parameter values are used in a Model and where BioCRNpyler found them is with the prett_print function of a ChemicalReactionNetwork or a Reaction with show_rates and show_keys both set to True.\n", " \n", " CRN.prett_print(show_rates = True, show_keys = True)\n", "\n", "show_rates toggles whether reaction rates are shown. The parameter values used in the rates will be shown below the rate function. show_keys toggles whether the ParameterKey used to search and find these rates is displayed. search_key is the key the Mechanism and component searched for in order to find the rate. found_key is the key the parameter was found in after defaulting.\n", "\n", "\n", "\n", "#### Parameter Dictionary Overview:\n", "A parameter dictionary should have the following forms (note that part_id and mechanism can be None):\n", "\n", "Using ParameterKeys (named tuples):\n", "\n", " parameters = {ParameterKey(mechanism = \"mechanism_name\", part_id = \"part_id\", name = \"parameter_name\"):param_val ...} #using ParameterKeys\n", " \n", "Using tuples or even just strings (for default parameters) shorthand is also valid:\n", "\n", " parameters = {(\"mechanism_name\", \"part_id\", \"parameter_name\"):val1, \"k\":default_val ...} \n", "\n", "#### Parameter Value Defaulting:\n", "Parameters can be passed into Components and Mixtures as both files and/or dictionaries. Parameters into Components will be used by reactions created by that Component:\n", "\n", " Component(... parameters = parameters, parameter_file = \"file_name\" ...)\n", "\n", "If a Component cannot find its own parameters, it will use parameters passed into the Mixture:\n", "\n", " Mixture(... parameters = parameters, parameter_file = \"file_name\" ...)\n", "\n", "At both the Mixture and Component levels, BioCRNpyler does nto require an exact keyword match. When Mechanisms are called by Components to produce reactions, they will initially look for\n", "\n", " ParameterKey(mechanism = \"mechanism_name\", part_id = \"part_id\", name = \"parameter_name\") --> param_val. \n", "\n", "If that particular parameter key cannot be found, the software will default to the following keys in this order: \n", "\n", " ParameterKey(mechanism = \"mechanism_type\", part_id = \"part_id\" , name = \"parameter_name\")\n", " ParameterKey(mechanism = None, part_id = \"part_id\" , name = \"parameter_name\")\n", " ParameterKey(mechanism = \"mechanism_name\", part_id = None , name = \"parameter_name\")\n", " ParameterKey(mechanism = \"mechanism_type\", part_id = None , name = \"parameter_name\")\n", " ParameterKey(mechanism = None, part_id = None , name = \"parameter_name\")\n", " \n", "As a note, mechanism_name refers to the .name variable of a Mechanism. mechanism_type refers to the .type variable of a Mechanism. Either of these can be used as a mechanism_id. This allows for models to be constructed easily using default parameter values and for parameters to be shared between different Mechanisms and/or Components.\n", "\n", "#### Units in BioCRNpyler\n", "\n", "The Parameter database in BioCRNpyler can also be used to import units for model parameters. Simply write your units in the parameter file (.csv/.tsv) as a new column titled \"unit\". To manually create a Parameter object with a unit, you can run:\n", "```\n", " new_parameter = Parameter(parameter_name=\"None\", parameter_value=\"1.0\", unit = \"M\")\n", " > new_paramter.unit == \"M\"\n", " > True\n", "```\n", "BioCRNpyler supports the following unit definitions. The string in paranthesis is the unit identifier that you should use for that particular unit: \n", "1. Time units: second (\"second\"), minute (\"minute\"), hour (\"hour\").\n", "2. Concentration units: nanomolar (\"nM\"), micromolar (\"uM\"), millimolar (\"mM\"), molar (\"M\"). \n", "3. Volume units: nanolitre (\"nL\"), microlitre (\"uL\"), millilitre (\"mL\"), litre (\"L\").\n", "4. Common parameter units: per second (\"per_second\"), per hour (\"per_hour\"), 1/(molar x second) (\"litre_per_mole_per_second\"), 1/(molar x hour) (\"litre_per_mole_per_hour\")\n", "\n", "To add support for any new unit of your choice, simply go to `units.py` in the `biocrnpyler/` source code and add your own function definition for a unit (you can use the existing functions to get an idea about how to create your own new definition).\n", "\n", "#### The ParameterDatabase and ParameterEntries\n", "Each Component and Mixture has its own ParameterDatabase full of ParameterEntries. In general, users are not expected to make these objects by hand. Instead, ParameterDatabases will be automatically populated with ParameterEntries using either a parameter_file or parameter_dictionary. However, they can be accessed and view by looking at Component.parameter_database and Mixture.parameter_database\n", "\n", "#### Multiple Parameter Files:\n", "Components and Mixtures can both have one more multiple parameter files by passing in a list of filenames instead of a single filename to the parameter_file keyword. Components use parameters loaded from their file(s) before defaulting to the file(s) supplied to a Mixture. The last file in any list will take precedent and overwrite parameter files which were written earlier.\n", "\n", "Below is an example csv with all the parameters for a tetR promoter undergoing Michaelis Menten transcription and translation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. The Parameter File\n", "In the following cell we look at an example parameter file that will run with no parameter defaulting." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "****Parameter File****\n", "mechanism_id\tpart_id\tparam_name\tparam_val\tunit\tcomments\n", "transcription_mm\tptet_tetR\tkb\t10.\tlitre_per_mole_per_hour\textra columns are okay!\n", "transcription_mm\tptet_tetR\tku\t.1\tper_hour\tThese are the parameters for transcription\n", "transcription_mm\tptet_tetR\tktx\t1.\t\t\n", "transcription_mm\tptet_leak\tktx\t.1\t\tThese are the parameters for transcription leak\n", "transcription_mm\tptet_leak\tku\t.1\t\t\n", "transcription_mm\tptet_leak\tkb\t.1\t\t\n", "one_step_cooperative_binding\tptet_tetR\tku\t.1\t\tThese are parameters for tetR dimerization and binding with the promoter\n", "one_step_cooperative_binding\tptet_tetR\tkb\t.1\t\t\n", "one_step_cooperative_binding\tptet_tetR\tcooperativity\t2\t\t\n", "translation_mm\tBCD\tktl\t2.0\t\tThese are parameters for translation\n", "translation_mm\tBCD\tku\t.25\tper_hour\t\n", "translation_mm\tBCD\tkb\t10\tlitre_per_mole_per_hour\t\n", "rna_degredation_mm\t\tkb\t10\t\t\"These are parameters for RNA degredation. \"\n", "rna_degredation_mm\t\tku\t.5\t\tThey will be the same for all RNAs because of parameter defaulting.\n", "rna_degredation_mm\t\tkdeg\t1.5\t\t\n" ] } ], "source": [ "from biocrnpyler import *\n", "perfect_param_file_name = \"Perfect Param File Example.tsv\"\n", "\n", "#Open and print the parameter file\n", "param_file = open(perfect_param_file_name)\n", "print(\"****Parameter File****\")\n", "print(param_file.read())\n", "param_file.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Use this parameter file to create a CRN" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "****Loaded Parameters****\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_tetR', name='kb') ==> 10.0\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_tetR', name='ku') ==> 0.1\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_tetR', name='ktx') ==> 1.0\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_leak', name='ktx') ==> 0.1\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_leak', name='ku') ==> 0.1\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_leak', name='kb') ==> 0.1\n", "ParameterKey(mechanism='one_step_cooperative_binding', part_id='ptet_tetR', name='ku') ==> 0.1\n", "ParameterKey(mechanism='one_step_cooperative_binding', part_id='ptet_tetR', name='kb') ==> 0.1\n", "ParameterKey(mechanism='one_step_cooperative_binding', part_id='ptet_tetR', name='cooperativity') ==> 2.0\n", "ParameterKey(mechanism='translation_mm', part_id='BCD', name='ktl') ==> 2.0\n", "ParameterKey(mechanism='translation_mm', part_id='BCD', name='ku') ==> 0.25\n", "ParameterKey(mechanism='translation_mm', part_id='BCD', name='kb') ==> 10.0\n", "ParameterKey(mechanism='rna_degredation_mm', part_id=None, name='kb') ==> 10.0\n", "ParameterKey(mechanism='rna_degredation_mm', part_id=None, name='ku') ==> 0.5\n", "ParameterKey(mechanism='rna_degredation_mm', part_id=None, name='kdeg') ==> 1.5\n", "\n", "****Resulting CRN****\n", "Notice that the found_key perfectly matches the search_key.\n", "\n", "Species(N = 13) = {\n", "protein[tetR] (@ 0), protein[reporter] (@ 0), rna[reporter] (@ 0), dna[reporter] (@ 0), complex[protein[Ribo]:rna[reporter]] (@ 0), complex[protein[RNAase]:rna[reporter]] (@ 0), complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]] (@ 0), [dna[reporter]:2x_protein[tetR]] (@ 0), complex[dna[reporter]:protein[RNAP]] (@ 0), complex[complex[protein[Ribo]:rna[reporter]]:protein[RNAase]] (@ 0), protein[Ribo] (@ 0), protein[RNAase] (@ 0), protein[RNAP] (@ 0), \n", "}\n", "\n", "Reactions (11) = [\n", "0. dna[reporter]+protein[RNAP] <--> complex[dna[reporter]:protein[RNAP]]\n", " Kf=k_forward * dna_reporter * protein_RNAP\n", " Kr=k_reverse * complex_dna_reporter_protein_RNAP_\n", " k_forward=0.1\n", " found_key=(mech=transcription_mm, partid=ptet_leak, name=kb).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=kb).\n", " k_reverse=0.1\n", " found_key=(mech=transcription_mm, partid=ptet_leak, name=ku).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=ku).\n", "\n", "1. complex[dna[reporter]:protein[RNAP]] --> dna[reporter]+rna[reporter]+protein[RNAP]\n", " Kf=k_forward * complex_dna_reporter_protein_RNAP_\n", " k_forward=0.1\n", " found_key=(mech=transcription_mm, partid=ptet_leak, name=ktx).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=ktx).\n", "\n", "2. 2protein[tetR]+dna[reporter] <--> [dna[reporter]:2x_protein[tetR]]\n", " Kf=k_forward * protein_tetR^2 * dna_reporter\n", " Kr=k_reverse * dna_reporter_protein_tetR_2x_\n", " k_forward=0.1\n", " found_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=kb).\n", " search_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=kb).\n", " k_reverse=0.1\n", " found_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=ku).\n", " search_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=ku).\n", "\n", "3. [dna[reporter]:2x_protein[tetR]]+protein[RNAP] <--> complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]]\n", " Kf=k_forward * dna_reporter_protein_tetR_2x_ * protein_RNAP\n", " Kr=k_reverse * complex_dna_reporter_protein_tetR_2x__protein_RNAP_\n", " k_forward=10.0\n", " found_key=(mech=transcription_mm, partid=ptet_tetR, name=kb).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=kb).\n", " k_reverse=0.1\n", " found_key=(mech=transcription_mm, partid=ptet_tetR, name=ku).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=ku).\n", "\n", "4. complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]] --> [dna[reporter]:2x_protein[tetR]]+rna[reporter]+protein[RNAP]\n", " Kf=k_forward * complex_dna_reporter_protein_tetR_2x__protein_RNAP_\n", " k_forward=1.0\n", " found_key=(mech=transcription_mm, partid=ptet_tetR, name=ktx).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=ktx).\n", "\n", "5. rna[reporter]+protein[Ribo] <--> complex[protein[Ribo]:rna[reporter]]\n", " Kf=k_forward * rna_reporter * protein_Ribo\n", " Kr=k_reverse * complex_protein_Ribo_rna_reporter_\n", " k_forward=10.0\n", " found_key=(mech=translation_mm, partid=BCD, name=kb).\n", " search_key=(mech=translation_mm, partid=BCD, name=kb).\n", " k_reverse=0.25\n", " found_key=(mech=translation_mm, partid=BCD, name=ku).\n", " search_key=(mech=translation_mm, partid=BCD, name=ku).\n", "\n", "6. complex[protein[Ribo]:rna[reporter]] --> rna[reporter]+protein[reporter]+protein[Ribo]\n", " Kf=k_forward * complex_protein_Ribo_rna_reporter_\n", " k_forward=2.0\n", " found_key=(mech=translation_mm, partid=BCD, name=ktl).\n", " search_key=(mech=translation_mm, partid=BCD, name=ktl).\n", "\n", "7. rna[reporter]+protein[RNAase] <--> complex[protein[RNAase]:rna[reporter]]\n", " Kf=k_forward * rna_reporter * protein_RNAase\n", " Kr=k_reverse * complex_protein_RNAase_rna_reporter_\n", " k_forward=10.0\n", " found_key=(mech=rna_degredation_mm, partid=None, name=kb).\n", " search_key=(mech=rna_degredation_mm, partid=rna_reporter, name=kb).\n", " k_reverse=0.5\n", " found_key=(mech=rna_degredation_mm, partid=None, name=ku).\n", " search_key=(mech=rna_degredation_mm, partid=rna_reporter, name=ku).\n", "\n", "8. complex[protein[RNAase]:rna[reporter]] --> protein[RNAase]\n", " Kf=k_forward * complex_protein_RNAase_rna_reporter_\n", " k_forward=1.5\n", " found_key=(mech=rna_degredation_mm, partid=None, name=kdeg).\n", " search_key=(mech=rna_degredation_mm, partid=rna_reporter, name=kdeg).\n", "\n", "9. complex[protein[Ribo]:rna[reporter]]+protein[RNAase] <--> complex[complex[protein[Ribo]:rna[reporter]]:protein[RNAase]]\n", " Kf=k_forward * complex_protein_Ribo_rna_reporter_ * protein_RNAase\n", " Kr=k_reverse * complex_complex_protein_Ribo_rna_reporter__protein_RNAase_\n", " k_forward=10.0\n", " found_key=(mech=rna_degredation_mm, partid=None, name=kb).\n", " search_key=(mech=rna_degredation_mm, partid=complex_protein_Ribo_rna_reporter_, name=kb).\n", " k_reverse=0.5\n", " found_key=(mech=rna_degredation_mm, partid=None, name=ku).\n", " search_key=(mech=rna_degredation_mm, partid=complex_protein_Ribo_rna_reporter_, name=ku).\n", "\n", "10. complex[complex[protein[Ribo]:rna[reporter]]:protein[RNAase]] --> protein[Ribo]+protein[RNAase]\n", " Kf=k_forward * complex_complex_protein_Ribo_rna_reporter__protein_RNAase_\n", " k_forward=1.5\n", " found_key=(mech=rna_degredation_mm, partid=None, name=kdeg).\n", " search_key=(mech=rna_degredation_mm, partid=complex_protein_Ribo_rna_reporter_, name=kdeg).\n", "\n", "]\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Create a Regulated Promoter\n", "Ptet = RegulatedPromoter(\"ptet\", regulators=[\"tetR\"], leak=True)\n", "reg_rep_assembly = DNAassembly(name=\"reporter\", promoter=Ptet, rbs=\"BCD\")\n", "tet = Protein(\"tetR\")\n", "components = [reg_rep_assembly, tet]\n", "myMixture = TxTlExtract(name=\"txtl\", parameter_file = perfect_param_file_name, components=components)\n", "\n", "\n", "#Print the parameter database created from the file\n", "print(\"\\n****Loaded Parameters****\")\n", "for param in myMixture.parameter_database:\n", " print(param.parameter_key, \"==>\", param.value)\n", "\n", "CRN = myMixture.compile_crn() \n", "print(\"\\n****Resulting CRN****\\nNotice that the found_key perfectly matches the search_key.\\n\")\n", "print(CRN.pretty_print(show_rates = True, show_keys = True))\n", "\n", "# Write to SBML\n", "CRN.write_sbml_file('model_with_perfect_params.xml')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will now look at an example of a parameter file that uses defaulting. If you were to fill in this file with full parameter signatures (mechanism_id, part_id, param_name, value), the errors at the bottom of the readout would slowly diminish. However, even without full values the file loads and runs. Although this example uses only the key \"param_name\" for default values, there exists a heirarchy of keys to allow for shared parameters between different Components and Mechanisms.\n", "\n", "The parameter key heirarchy (top takes priority):\n", "1) (mechanism_name, part_id, param_name)\n", "2) (mechanism_type, part_id, param_name)\n", "3) (part_id, param_name)\n", "4) (mechanism_name, param_name)\n", "5) (mechanism_type, param_name)\n", "6) (param_name)\n", "\n", "here the column \"mechanism_type\" can either be a Mechanism's type string Mechanism.type (eg \"transcription\") or its name string Mechanism.name (eg \"transcription_mm\"). " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "****Parameter File****\n", "param_name\tparam_val\tcomments\tmechanism_id\tpart_id\n", "ku\t1.0\tAny parameter called ku will default to this\t\t\n", "kb\t1.0\tDefault kb\t\t\n", "ktx\t2.0\tDefault ktx\t\t\n", "ktl\t3.0\tDefault ktl\t\t\n", "cooperativity\t2.0\tDefault cooperativity\t\t\n", "kdeg\t.5\tDefault degredation\t\t\n" ] } ], "source": [ "from biocrnpyler import *\n", "default_param_file_name = \"Default Param File Example.tsv\"\n", "\n", "#Open and print the parameter file\n", "param_file = open(default_param_file_name)\n", "print(\"****Parameter File****\")\n", "print(param_file.read())\n", "param_file.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### And use these parameters in a CRN - not all reactions of the same name share the same parameters!" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "****Loaded Parameters****\n", "ParameterKey(mechanism=None, part_id=None, name='ku') ==> 1.0\n", "ParameterKey(mechanism=None, part_id=None, name='kb') ==> 1.0\n", "ParameterKey(mechanism=None, part_id=None, name='ktx') ==> 2.0\n", "ParameterKey(mechanism=None, part_id=None, name='ktl') ==> 3.0\n", "ParameterKey(mechanism=None, part_id=None, name='cooperativity') ==> 2.0\n", "ParameterKey(mechanism=None, part_id=None, name='kdeg') ==> 0.5\n", "\n", "****Resulting CRN****\n", "Notice that only the name portion of parameter keys match.\n", "\n", "Species (12) = {0. [dna[reporter]:2x_protein[tetR]], 1. complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]], 2. protein[tetR], 3. protein[RNAP], 4. protein[reporter], 5. complex[protein[RNAase]:rna[reporter]], 6. complex[dna[reporter]:protein[RNAP]], 7. protein[RNAase], 8. rna[reporter], 9. complex[protein[Ribo]:rna[reporter]], 10. dna[reporter], 11. protein[Ribo]}\n", "Reactions (9) = [\n", "0. dna[reporter]+protein[RNAP] <--> complex[dna[reporter]:protein[RNAP]]\n", " Kf=k_forward * dna_reporter * protein_RNAP\n", " Kr=k_reverse * complex_dna_reporter_protein_RNAP\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=ku.\n", "\n", "1. complex[dna[reporter]:protein[RNAP]] --> dna[reporter]+rna[reporter]+protein[RNAP]\n", " Kf=k_forward * complex_dna_reporter_protein_RNAP\n", " k_forward=2.0\n", " found_key=(mech=None, partid=None, name=ktx).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=ktx.\n", " k_reverse=None\n", "\n", "2. 2protein[tetR]+dna[reporter] <--> [dna[reporter]:2x_protein[tetR]]\n", " Kf=k_forward * protein_tetR^2 * dna_reporter\n", " Kr=k_reverse * dna_reporter_2x_protein_tetR\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=ku.\n", "\n", "3. [dna[reporter]:2x_protein[tetR]]+protein[RNAP] <--> complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]]\n", " Kf=k_forward * dna_reporter_2x_protein_tetR * protein_RNAP\n", " Kr=k_reverse * complex_dna_reporter_2x_protein_tetR_protein_RNAP\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=ku.\n", "\n", "4. complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]] --> [dna[reporter]:2x_protein[tetR]]+rna[reporter]+protein[RNAP]\n", " Kf=k_forward * complex_dna_reporter_2x_protein_tetR_protein_RNAP\n", " k_forward=2.0\n", " found_key=(mech=None, partid=None, name=ktx).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=ktx.\n", " k_reverse=None\n", "\n", "5. rna[reporter]+protein[Ribo] <--> complex[protein[Ribo]:rna[reporter]]\n", " Kf=k_forward * rna_reporter * protein_Ribo\n", " Kr=k_reverse * complex_protein_Ribo_rna_reporter\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=translation_mm, partid=BCD, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=translation_mm, partid=BCD, name=ku.\n", "\n", "6. complex[protein[Ribo]:rna[reporter]] --> rna[reporter]+protein[reporter]+protein[Ribo]\n", " Kf=k_forward * complex_protein_Ribo_rna_reporter\n", " k_forward=3.0\n", " found_key=(mech=None, partid=None, name=ktl).\n", " search_key=(mech=translation_mm, partid=BCD, name=ktl.\n", " k_reverse=None\n", "\n", "7. rna[reporter]+protein[RNAase] <--> complex[protein[RNAase]:rna[reporter]]\n", " Kf=k_forward * rna_reporter * protein_RNAase\n", " Kr=k_reverse * complex_protein_RNAase_rna_reporter\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=rna_degredation_mm, partid=reporter, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=rna_degredation_mm, partid=reporter, name=ku.\n", "\n", "8. complex[protein[RNAase]:rna[reporter]] --> protein[RNAase]\n", " Kf=k_forward * complex_protein_RNAase_rna_reporter\n", " k_forward=0.5\n", " found_key=(mech=None, partid=None, name=kdeg).\n", " search_key=(mech=rna_degredation_mm, partid=reporter, name=kdeg.\n", " k_reverse=None\n", "\n", "]\n" ] } ], "source": [ "#Create a Regulated Promoter\n", "Ptet = RegulatedPromoter(\"ptet\", regulators=[\"tetR\"], leak=True)\n", "reg_rep_assembly = DNAassembly(name=\"reporter\", promoter=Ptet, rbs=\"BCD\")\n", "tet = Protein(\"tetR\")\n", "components = [reg_rep_assembly, tet]\n", "\n", "myMixture = TxTlExtract(name=\"txtl\", parameter_file = default_param_file_name, components=components)\n", "\n", "#Print the parameter dictionary created from the file\n", "print(\"\\n****Loaded Parameters****\")\n", "for param in myMixture.parameter_database:\n", " print(param.parameter_key, \"==>\", param.value)\n", " \n", "print(\"\\n****Resulting CRN****\\nNotice that only the name portion of parameter keys match.\\n\")\n", "print(myMixture.compile_crn().pretty_print(show_rates = True, show_keys = True))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setting Parameters at the component level\n", "Components can have their own parameter files instead of relying on the parameter files passed into a mixture. Components can also have the mixtures default parameters overwritten with a parameter dictionary. Below, we will create a DNAassembly which has custom parameters loaded in as a dictionary (this works the same as loading them with a file). We will put this in a Mixture with the default parameters from the above example. This example also helps illustrate how the parameter loading heirarchy works if you examine the final CRNs." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "#Create custom parameter dictionary for the ptet promoter. In this case, we will add specific leak parameters and\n", "ra_param_dict = {\n", " ParameterKey(mechanism = \"transcription_mm\", part_id = None, name = \"ku\"):33.33, #These parameters will take priority over single key parameters\n", " ParameterKey(mechanism = \"transcription_mm\", part_id = None, name = \"kb\"):.3333, \n", " ParameterKey(mechanism = \"transcription_mm\", part_id = None, name = \"ktx\"):3.333, \n", " ParameterKey(mechanism = \"transcription_mm\", part_id = \"ptet_leak\", name = \"ku\"):111.1, #these parameters will take priority over the ones above\n", " ParameterKey(mechanism = \"transcription_mm\", part_id = \"ptet_leak\", name = \"kb\"):.1111, \n", "}\n", "\n", "#Use the parameter_file keyword to update the parameters with a file.\n", "#Use the parameters keyword to update the parameters with a dictionary\n", "#If Use both: the dictionary takes precedent to the file if there are conflicts.\n", "Ptet = RegulatedPromoter(\"ptet\", regulators=[\"tetR\"], leak=True, parameters = ra_param_dict)\n", "reg_rep_assembly = DNAassembly(name=\"reporter\", promoter=Ptet, rbs=\"BCD\")\n", "tet = Protein(\"tetR\")\n", "components = [reg_rep_assembly, tet]\n", "myMixture = TxTlExtract(name=\"txtl\", parameter_file = default_param_file_name, components=components)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Mixture parameters come from the file" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "****Mixture Parameters****\n", "ParameterKey(mechanism=None, part_id=None, name='ku') ==> 1.0\n", "ParameterKey(mechanism=None, part_id=None, name='kb') ==> 1.0\n", "ParameterKey(mechanism=None, part_id=None, name='ktx') ==> 2.0\n", "ParameterKey(mechanism=None, part_id=None, name='ktl') ==> 3.0\n", "ParameterKey(mechanism=None, part_id=None, name='cooperativity') ==> 2.0\n", "ParameterKey(mechanism=None, part_id=None, name='kdeg') ==> 0.5\n" ] } ], "source": [ "print(\"\\n****Mixture Parameters****\")\n", "for param in myMixture.parameter_database:\n", " print(param.parameter_key, \"==>\", param.value)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Component level parameters come from the dictionary" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "****Ptet Parameters****\n", "ParameterKey(mechanism='transcription_mm', part_id=None, name='ku') ==> 33.33\n", "ParameterKey(mechanism='transcription_mm', part_id=None, name='kb') ==> 0.3333\n", "ParameterKey(mechanism='transcription_mm', part_id=None, name='ktx') ==> 3.333\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_leak', name='ku') ==> 111.1\n", "ParameterKey(mechanism='transcription_mm', part_id='ptet_leak', name='kb') ==> 0.1111\n" ] } ], "source": [ "### Component Parameters are different!\n", "print(\"\\n****Ptet Parameters****\")\n", "for param in Ptet.parameter_database:\n", " print(param.parameter_key, \"==>\", param.value)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The Compiled CRN uses Component level parameters if it can find them before defaulting to Mixture level Parameters" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Species (12) = {0. [dna[reporter]:2x_protein[tetR]], 1. complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]], 2. protein[tetR], 3. protein[RNAP], 4. protein[reporter], 5. complex[protein[RNAase]:rna[reporter]], 6. complex[dna[reporter]:protein[RNAP]], 7. protein[RNAase], 8. rna[reporter], 9. complex[protein[Ribo]:rna[reporter]], 10. dna[reporter], 11. protein[Ribo]}\n", "Reactions (9) = [\n", "0. dna[reporter]+protein[RNAP] <--> complex[dna[reporter]:protein[RNAP]]\n", " Kf=k_forward * dna_reporter * protein_RNAP\n", " Kr=k_reverse * complex_dna_reporter_protein_RNAP\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=ku.\n", "\n", "1. complex[dna[reporter]:protein[RNAP]] --> dna[reporter]+rna[reporter]+protein[RNAP]\n", " Kf=k_forward * complex_dna_reporter_protein_RNAP\n", " k_forward=2.0\n", " found_key=(mech=None, partid=None, name=ktx).\n", " search_key=(mech=transcription_mm, partid=ptet_leak, name=ktx.\n", " k_reverse=None\n", "\n", "2. 2protein[tetR]+dna[reporter] <--> [dna[reporter]:2x_protein[tetR]]\n", " Kf=k_forward * protein_tetR^2 * dna_reporter\n", " Kr=k_reverse * dna_reporter_2x_protein_tetR\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=one_step_cooperative_binding, partid=ptet_tetR, name=ku.\n", "\n", "3. [dna[reporter]:2x_protein[tetR]]+protein[RNAP] <--> complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]]\n", " Kf=k_forward * dna_reporter_2x_protein_tetR * protein_RNAP\n", " Kr=k_reverse * complex_dna_reporter_2x_protein_tetR_protein_RNAP\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=ku.\n", "\n", "4. complex[[dna[reporter]:2x_protein[tetR]]:protein[RNAP]] --> [dna[reporter]:2x_protein[tetR]]+rna[reporter]+protein[RNAP]\n", " Kf=k_forward * complex_dna_reporter_2x_protein_tetR_protein_RNAP\n", " k_forward=2.0\n", " found_key=(mech=None, partid=None, name=ktx).\n", " search_key=(mech=transcription_mm, partid=ptet_tetR, name=ktx.\n", " k_reverse=None\n", "\n", "5. rna[reporter]+protein[Ribo] <--> complex[protein[Ribo]:rna[reporter]]\n", " Kf=k_forward * rna_reporter * protein_Ribo\n", " Kr=k_reverse * complex_protein_Ribo_rna_reporter\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=translation_mm, partid=BCD, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=translation_mm, partid=BCD, name=ku.\n", "\n", "6. complex[protein[Ribo]:rna[reporter]] --> rna[reporter]+protein[reporter]+protein[Ribo]\n", " Kf=k_forward * complex_protein_Ribo_rna_reporter\n", " k_forward=3.0\n", " found_key=(mech=None, partid=None, name=ktl).\n", " search_key=(mech=translation_mm, partid=BCD, name=ktl.\n", " k_reverse=None\n", "\n", "7. rna[reporter]+protein[RNAase] <--> complex[protein[RNAase]:rna[reporter]]\n", " Kf=k_forward * rna_reporter * protein_RNAase\n", " Kr=k_reverse * complex_protein_RNAase_rna_reporter\n", " k_forward=1.0\n", " found_key=(mech=None, partid=None, name=kb).\n", " search_key=(mech=rna_degredation_mm, partid=reporter, name=kb.\n", " k_reverse=1.0\n", " found_key=(mech=None, partid=None, name=ku).\n", " search_key=(mech=rna_degredation_mm, partid=reporter, name=ku.\n", "\n", "8. complex[protein[RNAase]:rna[reporter]] --> protein[RNAase]\n", " Kf=k_forward * complex_protein_RNAase_rna_reporter\n", " k_forward=0.5\n", " found_key=(mech=None, partid=None, name=kdeg).\n", " search_key=(mech=rna_degredation_mm, partid=reporter, name=kdeg.\n", " k_reverse=None\n", "\n", "]\n" ] } ], "source": [ "myCRN = myMixture.compile_crn()\n", "print(myCRN.pretty_print(show_rates = True, show_keys = True))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }